﻿var spaceOb = {};
spaceArray = [];

var SpaceShip = function (name, shipClass, weapons, crew) {
    this.name = name;
    this.shipClass = shipClass;
    this.weapons = "phasers";
    this.crew = true;
    
};


spaceOb.add = function () {
    'use strict'
    var newName = document.getElementById("nameI");
    var newShipClass = document.getElementById("shipClassI");
    if (newName.value !== "" && newShipClass.value !== "") {
        
        var spaceHolder = new SpaceShip(newName.value, newShipClass.value);
     spaceArray.push(spaceHolder); 
     
     newName = "";
        newShipClass = "";
        spaceOb.writeItems();
    } else { alert("Type something!") };
}
spaceOb.edit = function() {
    'use strict'
    var editer = document.getElementbyId('bottom').innerHTML;


}
spaceOb.delete = function (index) {
        spaceArray.splice(index, 1);
};

spaceOb.writeItems = function () {
    'use strict'
    var sHolder = "<table class='table table-striped table-hover'>";
    for (var i in spaceArray) {
        if (spaceArray[i]) {
      
            sHolder += "<td>" + spaceArray[i].name + " " + spaceArray[i].shipClass + " " + "</td>";
            sHolder += '<td><button type="button" class="btn btn-block btn-danger" onclick="spaceOb.delete()">Delete</button></td>';
            sHolder += '<td><button type="button" class="btn btn-block btn-danger" onclick="spaceOb.edit">Edit</button><br></td>';
        }
    }
    sHolder += "</table>";
    document.getElementById("bottom").innerHTML = sHolder;
};

